﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPI.Entities.Interface;
using PPI.Mobile.Logic;

namespace PPI.ServiceLogic.Mobile
{
    /// <summary>
    /// Creats a SQL sentence that will autoexeceute when a table is deployed to the mobile
    /// </summary>
    public class LFillMobileTablesBase
    {
        protected List<IMobileTable> m_ListTables;
        private readonly string m_ConnectionKey;
        private readonly string m_ConnectionStringMobile;

        /// <summary>
        /// Lists all the clases implemented in  IFIllMobileTable, that allows us to get the created queries  
        /// </summary>
        /// <param name="connectionKey"></param>
        /// <param name="connectionStringMobile"></param>
        public LFillMobileTablesBase(string connectionKey, string connectionStringMobile)
        {
            m_ListTables = new List<IMobileTable>();
            m_ListTables.Add(new LXMissionStructures_PoleClass());
            m_ListTables.Add(new LXMissionStructures_PoleSpecies());
            m_ListTables.Add(new LXMissionStructures_PoleTreatments());
            m_ListTables.Add(new LXMissionStructures_TopType());
            m_ListTables.Add(new LVendor_Visit_Type());
            m_ListTables.Add(new LVendor());
            m_ListTables.Add(new LVendor_Project());
            m_ListTables.Add(new LVendor_Contacts());

            m_ConnectionKey = connectionKey;
            m_ConnectionStringMobile = connectionStringMobile;
        }

        /// <summary>
        /// Executes the queries in the  MobileDatabase that were created by the different data models.
        /// </summary>
        public void FillTables()
        {
            foreach (IMobileTable table in m_ListTables)
            {
                LMobileDatabase.ExecuteQuery(table.CreateInsertMobileQuery(m_ConnectionKey), m_ConnectionStringMobile); 
            }
        }
    }
}
